
    <!DOCTYPE html>
    <html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
    <head>
        <!--公用头部-->
        <th:block th:replace="common/head::commonHead(代码生成器-小邑)" />
        <style>
            .layui-card {
                margin: 10px;
            }

            .layui-card:last-child {
                margin-bottom: 10px;
            }

            .layui-card-header {
                border-bottom: 1px solid #e6e6e6;
            }
        </style>
    </head>
    <!--公用js-->
    <th:block th:replace="common/head::commonJs" />
<body>
<form class="layui-form" action="">
    <div class="layui-fluid layui-fluid-btn">
        <!-- 生成信息 -->
        <div class="layui-row">
            <!-- 左侧 -->
            <div class="layui-col-md6">
                <div class="layui-card">
                    <div class="layui-card-header">基本信息Ⅰ</div>
                    <div class="layui-card-body layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <div class="layui-form-item">
                                <label class="layui-form-label">
                                    包路径 <i class="layui-icon layui-icon-about" lay-tips="生成在哪个包下，例如：com.yy.permissions_general.module"></i>
                                </label>
                                <div class="layui-input-block">
                                    <input type="text" name="packageName" required  lay-verify="required"  value="com.yy.permissions_general.module" placeholder="请输入生成包路径" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md12">
                            <div class="layui-form-item">
                                <label class="layui-form-label">
                                    模块名称 <i class="layui-icon layui-icon-about" lay-tips="利用模块名来划分功能"></i>
                                </label>
                                <div class="layui-input-block">
                                    <input type="text" name="moduleName" required  lay-verify="required" placeholder="请输入模块名称" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md12">
                            <div class="layui-form-item">
                                <label class="layui-form-label">
                                    表前缀 <i class="layui-icon layui-icon-about" lay-tips="输入的表前缀生成过程中将会被移除"></i>
                                </label>
                                <div class="layui-input-block">
                                    <input type="text" name="tablePrefix" required value="sys_" lay-verify="required"
                                           placeholder="请输入表前缀" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 右侧 -->
            <div class="layui-col-md6">
                <div class="layui-card">
                    <div class="layui-card-header">基本信息Ⅱ</div>
                    <div class="layui-card-body layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <div class="layui-form-item">
                                <label class="layui-form-label">作者</label>
                                <div class="layui-input-block">
                                    <input type="text" name="author" required value="YY" lay-verify="required" placeholder="输入注释作者信息" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md12">
                            <div class="layui-form-item">
                                <label class="layui-form-label">生成模板</label>
                                <div class="layui-input-block">
                                    <select name="template" lay-verify="required">
                                        <option value="">请选择模板</option>
                                        <option value="MyBatis-Plus" selected>MyBatis-Plus</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md12">
                            <div class="layui-form-item">
                                <label class="layui-form-label">生成页面</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="createPage" lay-skin="switch" lay-text="开启|关闭" checked>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 字段列表 -->
        <div class="layui-row">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <table id="fieldTable" lay-filter="fieldTable"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="form-group-bottom">
        <button type="button" id="execute" class="xy-btn xy-btn-primary" lay-submit="" lay-filter="execute">
           提交
        </button>
        <button type="button" id="closeDialog" class="xy-btn ">
            取消
        </button>
    </div>
    </form>

    <script type="text/html" id="toolBar">
        <input type="checkbox" class="queryField" lay-skin="primary">
    </script>

    <!-- js -->
    <script>
        layui.use(['table', 'jquery', 'form', 'util'], function () {
            var table = layui.table,
                form = layui.form,
                $ = layui.jquery,
                util = layui.util;
            util.fixbar({
                top: true //返回顶部
                , css: {right: 50, bottom: 50}
                , bgcolor: '#3b7cd8'
                , click: function (type) {

                }
            });

            table.render({
                elem: '#fieldTable'
                , url: basePath + '/generator/getFields'
                , page: false
                , where: {
                    tableName: utils.request.getQueryString('tableName')
                }
                , cellMinWidth: 100
                , cols: [[
                    {field: 'fieldName', title: '字段名称'}
                    ,{field: 'fieldComment', title: '字段描述'}
                    ,{field: 'dataType', title: 'SQL类型'}
                    ,{title:'查询', event: 'queryField', width: 60, align: 'center', toolbar: '#toolBar'}
                ] ]
            });


            // 表单事件监听
            form.on('submit(execute)', function(data) {
                // 获取字段信息
                data.field.fields = layui.table.cache['fieldTable'];
                // 处理开关的选项
                data.field.createPage = data.field.createPage === "on";
                data.field.createSql = data.field.createSql === "on";
                data.field.createSwagger = data.field.createSwagger === "on";
                // 获取表名
                data.field.tableName = utils.request.getQueryString('tableName');
                // 发送请求
                download(basePath+ '/generator/execute','code.zip',data.field);
                return false;
            });

            // 监听行工具事件
            table.on('tool(fieldTable)', function(obj) {
                var data = obj.data;
                // 页面查询字段
                if (obj.event === 'queryField') {
                    var flag = $(obj.tr).find('.queryField').is(":checked");
                    data.queryField = flag === true;
                    var rowIndex = obj.tr[0].dataset.index;
                        layui.$.extend(table.cache["fieldTable"][rowIndex],data);
                }
            });

            // 取消 关闭弹窗
            $('#closeDialog').on('click',function () {
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            });

        });
    </script>

</body>
</html>